package cn.itsource.pethome.echarts.controller;

import cn.itsource.pethome.org.domain.po.ShopPO;
import cn.itsource.pethome.org.domain.po.ShopVO;
import cn.itsource.pethome.org.service.IShopService;
import cn.itsource.pethome.util.AjaxResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

@RequestMapping("/echarts")
@RestController
public class EchartsController {
    @Autowired
    private IShopService shopService;

    @GetMapping("/shopRegisterCount")
    public AjaxResult shopRegisterCount(){
        List<ShopPO> shopPOS = shopService.shopRegisterCount();
        //只去获取 num 返回一个list
        List<Long> nums = shopPOS.stream().map(ShopPO::getNum).collect(Collectors.toList());
        //只去获取 name 返回一个list
        List<String> names = shopPOS.stream().map(ShopPO::getName).collect(Collectors.toList());

        List<ShopVO> shopVOS = new ArrayList<>();
        for (ShopPO shopPO : shopPOS) {
            shopVOS.add(new ShopVO(shopPO.getNum(),shopPO.getName()));
        }
        Map<String,Object> result = new HashMap<>();
        result.put("num",nums);
        result.put("name",names);
        result.put("data",shopVOS);
        return AjaxResult.me().setData(result);
    }
}
